package com.sentiment.servlet;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.log4j.Logger;

import com.sentiment.config.Config;
import com.sentiment.entrance.EnterToKmp;
import com.sentiment.port.EnterTo;

@SuppressWarnings("serial")
public class ProgressServlet extends HttpServlet {
	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse
	 *      response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		// TODO Auto-generated method stub
		doPost(request, response);
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse
	 *      response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		// TODO Auto-generated method stub
		Logger logger = Config.getLogger(this.getClass());
		logger.info("ProgressServlet begin");
		// statusStr用于存储每一步返回的状态信息字符串
		String statusStr;
		// 切换是调用lsh还是kmp
		EnterTo launch = new EnterToKmp();
		response.setCharacterEncoding("utf-8");
		PrintWriter out = response.getWriter();
		switch (Integer.valueOf(request.getParameter("status"))) {
		case 0:
			statusStr = launch.stepOne(request.getParameter("srcId"));
			out.print(launch.getJson(statusStr, 10));
			break;
		case 1:
			statusStr = launch.stepTwo();
			out.print(launch.getJson(statusStr, 30));
			break;
		case 2:
			statusStr = launch.stepThree();
			out.print(launch.getJson(statusStr, 60));
			break;
		case 3:
			statusStr = launch.stepFour();
			out.print(launch.getJson(statusStr, 80));
			break;
		case 4:
			statusStr = launch.stepFive();
			out.print(launch.getJson(statusStr, 100));
			break;
		}
		logger.info("-----doPost执行完一次-----");
		out.close();
	}
}